//
//  EXAppdelegate.swift
//  ParkManage
//
//  Created by cf on 2020/9/21.
//  Copyright © 2020 diligrp. All rights reserved.
//

import Foundation

// 极光
extension AppDelegate: JPUSHRegisterDelegate {
    
    func application(
        _ application: UIApplication,
        didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        JPUSHService.registerDeviceToken(deviceToken)
    }
    
    func application(
        _ application: UIApplication,
        didFailToRegisterForRemoteNotificationsWithError error: Error) {
        print("did Fail To Register For Remote Notifications With Error")
    }
    
    func jpushNotificationCenter(
        _ center: UNUserNotificationCenter!,
        willPresent notification: UNNotification!,
        withCompletionHandler completionHandler: ((Int) -> Void)!) {
        
        let userInfo = notification.request.content.userInfo
        if notification.request.trigger is UNPushNotificationTrigger {
            JPUSHService.handleRemoteNotification(userInfo)
        }
        // 需要执行这个方法，选择是否提醒用户，有Badge、Sound、Alert三种类型可以选择设置
        completionHandler(Int(UNNotificationPresentationOptions.alert.rawValue))
    }
    
    func jpushNotificationCenter(
        _ center: UNUserNotificationCenter!,
        didReceive response: UNNotificationResponse!,
        withCompletionHandler completionHandler: (() -> Void)!) {
        
        let userInfo = response.notification.request.content.userInfo
        if response.notification.request.trigger is UNPushNotificationTrigger {
            JPUSHService.handleRemoteNotification(userInfo)
        }
        // 系统要求执行这个方法
        completionHandler()
    }
    
    func jpushNotificationCenter(
        _ center: UNUserNotificationCenter!,
        openSettingsFor notification: UNNotification!) {
        
    }
}

// 友盟回调
extension AppDelegate {
    
    func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
        
        let result = UMSocialManager.default()?.handleOpen(url, options: options)
        
        if !(result ?? false) {
            
        }
        
        return result ?? false
    }
}
